package dk.aiszone.lang.sql;

import static dk.aiszone.lang.sql.SQLHelper.escapeReservedWord;
import dk.aiszone.lang.sql.interfaces.SQLConstraint;

/*pp*/class SQLFieldList extends SQLList {

    /* pp */SQLFieldList(SQLAssignableField field) {
        super(new HolderClass(field));
    }

    @Override
    protected String getSeperator() {
        return ", ";
    }

    private static class HolderClass implements SQLConstraint {

        private final SQLAssignableField field;

        /* pp */HolderClass(SQLAssignableField field) {
            this.field = field;
        }

        @Override
        public SQLAssignableField getAssignableField() {
            return field;
        }

        @Override
        public SQLResult prepareSQL(SQLResult sql) {
            return sql.append(escapeReservedWord(field.getField()));
        }

        @Override
        public String toPreparedStatement() {
            return toSQL();
        }

        @Override
        public String toSQL() {
            return field.getField();
        }
    }
}